home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / c_jitter.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  87 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  C_JITTER.H - Color Reduction Filter Class
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. #ifndef _C_JITTER_H
  39. #define _C_JITTER_H
  40.  
  41. // Adapted from: Bragg, D. [1992]. "A Simple Color Reduction 
  42. //               Filter", in Graphics Gems III (D. Kirk, 
  43. //               Ed.), Academic Press, San Diego, CA, 20 - 
  44. //               22, 429 - 431
  45.  
  46. #include <stdlib.h>
  47. #include "color.h"
  48.  
  49. static const int C_LargeNum = 1024;
  50. static const int C_TableSize = 1024;
  51. static const int C_Mask = C_TableSize - 1;
  52.  
  53. class ColorJitter       // Color reduction filter
  54. {
  55.   private:
  56.     double *pxrand;     // Jitter lookup table pointer
  57.     double *pyrand;     // Jitter lookup table pointer
  58.     int noise;          // Noise level ( 0 - 8 )
  59.     int *pirand;        // Jitter lookup table pointer
  60.     BOOL status;        // Object status
  61.  
  62.     double JitterX( int x, int y, int band )
  63.     {
  64.       return pxrand[((x + (y << 2)) + pirand[(x + band) &
  65.           C_Mask]) & C_Mask];
  66.     }
  67.  
  68.     double JitterY( int x, int y, int band )
  69.     {
  70.       return pyrand[((y + (x << 2)) + pirand[(y + band) &
  71.           C_Mask]) & C_Mask];
  72.     }
  73.  
  74.   public:
  75.     ColorJitter();
  76.  
  77.     ~ColorJitter();
  78.  
  79.     BOOL GetStatus() { return status; }
  80.     int GetNoiseLevel() { return noise; }
  81.     void SetNoiseLevel( int n ) { noise = n % 9; }
  82.     void Reduce( ColorRGB *, int, int );
  83. };
  84.  
  85. #endif
  86.  
  87.